package com.imooc.miaosha.util;

import com.imooc.miaosha.common.Const;
import redis.clients.jedis.HostAndPort;
import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisCluster;
import redis.clients.jedis.JedisPoolConfig;

import java.util.HashSet;
import java.util.Set;

public class JedisClusterUtil {
    private static JedisCluster jedisCluster;
    static {
        Set<HostAndPort>hostAndPortsSet=new HashSet<HostAndPort>();
//        hostAndPortsSet.add(new HostAndPort(Const.REDIS_1_CONFIG.IP,Const.REDIS_1_CONFIG.PORT));
        hostAndPortsSet.add(new HostAndPort(Const.REDIS_2_CONFIG.IP,Const.REDIS_2_CONFIG.PORT));
        JedisPoolConfig jedisPoolConfig=new JedisPoolConfig();
        jedisPoolConfig.setMaxWaitMillis(2000);
        jedisPoolConfig.setMaxTotal(2000);
        jedisPoolConfig.setMaxIdle(500);
        jedisPoolConfig.setMinIdle(0);
        jedisCluster=new JedisCluster(hostAndPortsSet,jedisPoolConfig);
    }
    public static JedisCluster getResource(){
        return jedisCluster;
    }
}
